using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interactivity;

namespace LogoFX.Controls
{
    public class SpacebarFixBehavior:Behavior<TextBox>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.KeyDown += new System.Windows.Input.KeyEventHandler(AssociatedObject_KeyDown);
        }

        void AssociatedObject_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Space)
            {
                e.Handled = true;
                (sender as TextBox).SelectedText = " ";
            }
        }
    }
}